import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:testshop/pages/cart_page.dart';
import 'package:testshop/pages/category_page.dart';
import 'package:testshop/pages/home_page.dart';
import 'package:testshop/pages/member_page.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final List<BottomNavigationBarItem> bottomtabs = [
    BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
    BottomNavigationBarItem(icon: Icon(Icons.search), label: '分类'),
    BottomNavigationBarItem(icon: Icon(Icons.shopping_cart), label: '购物车'),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.profile_circled), label: '会员中心'),
  ];

  final List tabBodis = [HomePage(), CategotyPage(), CartPage(), MemberPage()];

  int currentPosition = 0;
  var curpage;

  @override
  void initState() {
    currentPosition = 0;
    curpage = tabBodis[currentPosition];

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
      bottomNavigationBar: BottomNavigationBar(
        items: bottomtabs,
        type: BottomNavigationBarType.fixed,
        currentIndex: currentPosition,
        onTap: (index) {
          setState(() {
            currentPosition = index;
            curpage = tabBodis[currentPosition];
          });
        },
      ),
      body: curpage,
    );
  }
}
